package com.op.studyingliteapp.database;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

import com.op.studyingliteapp.BuildConfig;
import com.op.studyingliteapp.database.table.CourseNotifTable;
import com.op.studyingliteapp.database.table.CourseTable;
import com.op.studyingliteapp.database.table.NoteTable;
import com.op.studyingliteapp.database.table.SeminarTable;

/**
 * SQLiteOpenHelper
 * 
 * @author Michael
 * @date Jun 23, 2015
 */
public class DBHelper extends SQLiteOpenHelper {

	private static final String TAG = DBHelper.class.getSimpleName();

	private static final String DATABASE_PREFIX = "studyingliteapp.db";

	private static final int DATABASE_VERSION = 1;

	public DBHelper(Context context, String userId) {
		this(context, DATABASE_PREFIX + userId + ".db", null, DATABASE_VERSION);
	}

	public DBHelper(Context context, String name, CursorFactory factory, int version) {
		super(context, name, factory, version);
		if (BuildConfig.DEBUG) {
			Log.d(TAG, "new DBHelper");
		}
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		if (BuildConfig.DEBUG) {
			Log.d(TAG, "Creating database");
		}
		CourseTable.onCreate(db);
		 CourseNotifTable.onCreate(db);
		 SeminarTable.onCreate(db); 
		 NoteTable.onCreate(db);
//		 ResourceTable.onCreate(db);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		if (BuildConfig.DEBUG) {
			Log.d(TAG, "Upgrading database");
		}
		CourseTable.onUpgrade(db, oldVersion, newVersion);
		 CourseNotifTable.onUpgrade(db, oldVersion, newVersion);
		 NoteTable.onUpgrade(db, oldVersion, newVersion);
//		 ResourceTable.onUpgrade(db, oldVersion, newVersion);
		 SeminarTable.onUpgrade(db, oldVersion, newVersion);
	}

}
